import 'package:flutter/material.dart';
import 'package:kugou/src/bloc/new_sing_rank_bloc.dart';
import 'package:kugou/src/models/new_sing_rank.dart';
import 'package:carousel_slider/carousel_slider.dart';

class ListenerPage extends StatefulWidget {
  @override
  _ListenerPageState createState() => _ListenerPageState();
}

class _ListenerPageState extends State<ListenerPage> {
  @override
  Widget build(BuildContext context) {
    newSingRankBloc.getNewSingRank();
    return ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: StreamBuilder(
          stream: newSingRankBloc.newSingRank,
          builder: (context, AsyncSnapshot<NewSingRank> snapshot) {
            if (snapshot.hasData) {
              return this._buildContent(snapshot.data, context);
            } else {
              return Container();
            }
          },
        ));
  }

  Widget _buildContent(NewSingRank data, context) {
    var images = <Widget>[];
    data.banner.forEach((item) {
      images.add(Container(
          padding: EdgeInsets.all(2),
          child: ClipRRect(
            child: Image.network(
              item.imgurl,
              fit: BoxFit.fill,
            ),
            borderRadius: BorderRadius.circular(5),
          )));
    });
    return Stack(
        alignment: AlignmentDirectional.topCenter,
        fit: StackFit.expand,
        children: [
          Positioned(
            top: 0,
            left: 0,
            right: 0,
            child: CarouselSlider(
              height: 150,
              items: images,
              autoPlay: true,
              reverse: true,
            ),
          ),
          Positioned(
            top: 140,
            left: 0,
            right: 0,
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                      topRight: Radius.circular(10),
                      topLeft: Radius.circular(10))),
              height: MediaQuery.of(context).size.height,
            ),
          )
        ]);
  }
}
